package com.yingside.game;

import java.util.ArrayList;
import java.util.List;

public class Hero {
    private String name;
    private int hp;
    private int attack;
    private int defence;
    private int ownMoney;
    private List<Weapon> weaponBag;
    private List<Armor> armorBag;
    private List<Shield> shieldBag;
    private List<Shoes> shoesBag;
    private Equipment equipment;

    public Hero() {
    }

    public Hero(String name, int hp, int attack, int defence, int ownMoney) {
        this.name = name;
        this.hp = hp;
        this.attack = attack;
        this.defence = defence;
        this.ownMoney = ownMoney;
        weaponBag = new ArrayList<>();
        armorBag = new ArrayList<>();
        shieldBag = new ArrayList<>();
        shoesBag = new ArrayList<>();
        equipment = new Equipment();
    }

    public void fight(Enemy m){
        System.out.println(this.name + ",提着大刀，冲向:" + m.getName());
        m.injured(this);
    }

    public int injured(Enemy m){
        int lostLife = m.getAttack() - this.defence;
        if(lostLife < 1){
            lostLife = 1; //至少减1滴血
        }
        System.out.println("-------------------" + this.name + " 受伤了-------------------");
        System.out.println("啊啊啊~~~");
        System.out.println("减少血量:" + lostLife);
        this.hp -= lostLife;

        System.out.println("剩余血量:" + this.hp);
        System.out.println("-------------------" + this.name + " 受伤了-------------------");
        return lostLife;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public int getAttack() {
        return attack;
    }

    public void setAttack(int attack) {
        this.attack = attack;
    }

    public int getDefence() {
        return defence;
    }

    public void setDefence(int defence) {
        this.defence = defence;
    }
    public int getOwnMoney() {
        return ownMoney;
    }

    public void setOwnMoney(int ownMoney) {
        this.ownMoney = ownMoney;
    }

    public List<Weapon> getWeaponBag() {
        return weaponBag;
    }

    public void setWeaponBag(List<Weapon> weaponBag) {
        this.weaponBag = weaponBag;
    }

    public Equipment getEquipment() {
        return equipment;
    }

    public void setEquipment(Equipment equipment) {
        this.equipment = equipment;
    }

    public List<Armor> getArmorBag() {
        return armorBag;
    }

    public void setArmorBag(List<Armor> armorBag) {
        this.armorBag = armorBag;
    }

    public List<Shield> getShieldBag() {
        return shieldBag;
    }

    public void setShieldBag(List<Shield> shieldBag) {
        this.shieldBag = shieldBag;
    }

    public List<Shoes> getShoesBag() {
        return shoesBag;
    }

    public void setShoesBag(List<Shoes> shoesBag) {
        this.shoesBag = shoesBag;
    }

    public void dressEquipment(Weapon weapon) {
        //判断英雄已经装备了武器
        if(this.getEquipment().getWeapon() != null){
            //减去已经装备的武器的属性值
            this.setAttack(this.getAttack() - this.getEquipment().getWeapon().getEffect());
            //注意，这里应该先把身上的武器放入到背包中，然后再讲身上的武器设置为null
            this.getWeaponBag().add(this.getEquipment().getWeapon());
            this.getEquipment().setWeapon(null);
        }
        //无论有没有装备武器，都需要把背包中的武器装备上
        this.getEquipment().setWeapon(weapon);
        //英雄自身的属性会受影响
        this.setAttack(this.getAttack() + weapon.getEffect());
        //删除背包中的武器
        this.getWeaponBag().remove(weapon);

    }

    public void dressEquipment(Armor armor) {
    }
}
